namespace Chaliy.Syndication.UnitTests.MediaRss
{
	using System;
	using System.Xml.XPath;
	using Xunit;
    using XunitExt;
	using Chaliy.Syndication.MediaRss;
		
	public class When_Write_Media_Content
	{        
		[Fact]
        public void Serializer_Should_Write_Url_Attribute()
		{			
            const string etalonContentUrl = "http://example.com/media.jpeg";

			MediaContent content 
				= new MediaContent
			{
                Url = new Uri(etalonContentUrl)
			};

            content
                .ShouldMatchMedia("/media:content/@url", "Media Content SHOULD have URL attribute")
                .Value.ShouldEqual(etalonContentUrl);
		}

        [Fact]
        public void Serializer_Should_Write_FileSize_Attribute_If_Specified()
        {
            const int etalonFileSize = 189;

            MediaContent content
                = new MediaContent
                {
                    FileSize = etalonFileSize
                };

            content
                .ShouldMatchMedia("/media:content/@fileSize", "Media Content SHOULD have fileSize attribute")
                .ValueAsInt.ShouldEqual(etalonFileSize);
        }

        [Fact]
        public void Serializer_Should_Not_Write_FileSize_Attribute_If_Null_Specified()
        {
            MediaContent content
                = new MediaContent
                {
                    FileSize = null
                };

            content
                .ShouldNotMatchMedia("/media:content/@fileSize", "Media Content SHOULD NOT have fileSize attribute");
        }

        [Fact]
        public void Serializer_Should_Write_Type_Attribute_If_Specified()
        {
            const string etalonContentType = "video/quicktime";

            MediaContent content
                = new MediaContent
                {
                    Type = etalonContentType
                };

            content
                .ShouldMatchMedia("/media:content/@type", "Media Content SHOULD have type attribute")
                .Value.ShouldEqual(etalonContentType);
        }

        [Fact]
        public void Serializer_Should_Not_Write_Type_Attribute_If_Null_Specified()
        {
            MediaContent content
                = new MediaContent
                {
                    Type = null
                };

            content
                .ShouldNotMatchMedia("/media:content/@type", "Media Content SHOULD NOT have type attribute");
        }

        [Theory]
        [InlineData(MediaMedium.Video, "video")]
        [InlineData(MediaMedium.Image, "image")]
        [InlineData(MediaMedium.Executable, "executable")]
        [InlineData(MediaMedium.Document, "document")]
        [InlineData(MediaMedium.Audio, "audio")]
        public void Serializer_Should_Write_Valid_Medium_Value(MediaMedium medium, string expectedValue)
        {
            MediaContent content
                = new MediaContent
                {
                    Medium = medium
                };

            content
                .ShouldMatchMedia("/media:content/@medium", "Media Content SHOULD have medium attribute")
                .Value.ShouldEqual(expectedValue);
        }

        [Fact]
        public void Serializer_Should_Not_Write_Medium_Attribute_If_None_Specified()
        {
            MediaContent content
                = new MediaContent
                {
                    Medium = MediaMedium.None
                };

            content
                .ShouldNotMatchMedia("/media:content/@medium", "Media Content SHOULD NOT have medium attribute");
        }

        [Fact]
        public void Serializer_Should_Throw_Serialization_Exception_If_Undefined_Medium_Specified()
        {
            MediaContent content
                = new MediaContent
                {
                    Medium = (MediaMedium)1589
                };

            content.ShouldThrowSerializationException();
        }
	}
}
